<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打扫请求</title>
    <style>
        .checkbox-container {
            margin-bottom: 20px;
        }
        .checkbox-container label {
            display: block;
            margin-bottom: 5px;
        }
    </style>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            fetch('/get-room-numbers')
                .then(response => response.json())
                .then(data => {
                    const container = document.getElementById('roomNumberContainer');
                    data.forEach(room => {
                        const div = document.createElement('div');
                        div.className = 'checkbox-container';
                        const checkbox = document.createElement('input');
                        checkbox.type = 'checkbox';
                        checkbox.value = room.roomNumber;
                        checkbox.id = 'room-' + room.roomNumber;
                        const label = document.createElement('label');
                        label.htmlFor = 'room-' + room.roomNumber;
                        label.textContent = room.roomNumber;
                        div.appendChild(checkbox);
                        div.appendChild(label);
                        container.appendChild(div);
                    });
                })
                .catch(error => {
                    console.error('Error:', error);
                });
        });

        function sendCleaningRequest() {
            const checkboxes = document.querySelectorAll('#roomNumberContainer input[type="checkbox"]:checked');
            const roomNumbers = Array.from(checkboxes).map(checkbox => checkbox.value);

            fetch('/send-cleaning-request', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ roomNumbers: roomNumbers })
            })
            .then(response => response.text())
            .then(data => {
                alert(data);
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }
    </script>
</head>
<body>
    <h1>打扫请求</h1>
    <div id="roomNumberContainer">
        <!-- 复选框将通过AJAX动态加载 -->
    </div>
    <button onclick="sendCleaningRequest()">发送打扫请求</button>
</body>
</html>
